function [T,M,Q]=Matrices(m11decis,m12decis,m21decis,m22decis,w1decis,w2decis,grid,nw,pi1)

for i=1:nw
    for j=1:nw
      G(i,j)=grid(j);
      M11(i,j)=interp1(grid,m11decis,grid(i),'spline');
      M12(i,j)=interp1(grid,m12decis,grid(i),'spline');
      M21(i,j)=interp1(grid,m21decis,grid(i),'spline');
      M22(i,j)=interp1(grid,m22decis,grid(i),'spline');
    end
end

for i=1:nw
   for j=1:nw
       if G(i,j)==w1decis(i)
            T11(i,j)=pi1;
            Q11(i,j)=pi1*M11(i,j);
       else
            T11(i,j)=0;
            Q11(i,j)=0;
       end
   
      if G(i,j)==w1decis(i)
           T12(i,j)=1-pi1;
           Q12(i,j)=(1-pi1)*M12(i,j);
      else
           T12(i,j)=0;
           Q12(i,j)=0;
      end
      
      if G(i,j)==w2decis(i)
           T21(i,j)=pi1;
           Q21(i,j)=(pi1)*M21(i,j);
      else
           T21(i,j)=0;
           Q21(i,j)=0;
      end
      
      if G(i,j)==w2decis(i)
          T22(i,j)=1-pi1;
          Q22(i,j)=(1-pi1)*M22(i,j);
      else
          T22(i,j)=0;
          Q22(i,j)=0;
      end
      
   end
end

T=[T11 T12; T21 T22]; % matrix of transition probabilities
M=[M11 M12; M21 M22]; % matrix of Stochastic discount factors
Q=[Q11 Q12; Q21 Q22]; % matrix of Arrow Debreu prices
